//
//  popTransitionAnimation.m
//  练习转场动画
//
//  Created by 苗钧豪 on 16/8/23.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "popTransitionAnimation.h"
#import "ViewController.h"
#import "nextViewController.h"
@implementation popTransitionAnimation
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    ViewController *vc = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    nextViewController *nVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    [containerView addSubview:vc.view];
    vc.VCimgview.hidden = YES;
    UIView *snapView = [nVC.nVCimgview snapshotViewAfterScreenUpdates:NO];
    snapView.frame = nVC.nVCimgview.frame;
    [containerView addSubview:snapView];
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        [containerView layoutIfNeeded];
        snapView.frame = vc.VCimgview.frame;
    } completion:^(BOOL finished) {
        vc.VCimgview.hidden = NO;
        [snapView removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];
}
@end
